package damas2;

/*
 * Damas2AboutBox.java
 */



import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import javax.swing.JOptionPane;

public class Estatistica extends javax.swing.JDialog {

    double porcentagem;
    String[][] ranking = new String[100][100];


    public Estatistica(java.awt.Frame parent, Jogador jogador) {
        super(parent);
        initComponents();
        getRootPane().setDefaultButton(closeButton);
        lbl_nome.setText(jogador.getNome());
        lbl_partidas.setText(Integer.toString(jogador.getPartidas()));
        lbl_vitoria.setText(Integer.toString(jogador.getVitorias()));
        if (jogador.getPartidas()==0){
            porcentagem = 0; }
        else {
            porcentagem = (jogador.getVitorias()*100)/jogador.getPartidas(); }
        lbl_porcentagem.setText(Double.toString(porcentagem));
        preenche_ranking();
    }

    private void preenche_ranking() {
        String linha;
        FileInputStream stream;
        try {
            int i=0;
            stream = new FileInputStream("Estatistica/RANKING.rkg");
            InputStreamReader streamReader = new InputStreamReader(stream);
            BufferedReader reader = new BufferedReader(streamReader);
            try {
                while (reader.ready()) {
                    linha = reader.readLine();
                    txt_ranking.append(linha+"\n");
                    String[] lista = linha.split(" ");
                    ranking[i][0] = lista[0];
                    int indice = linha.lastIndexOf(' ');
                    ranking[i][1] = linha.substring(indice);
                    i++;
                }
            } catch (IOException ex) { }

        } catch (FileNotFoundException ex) {
            JOptionPane.showMessageDialog(null, "Erro ao carregar ranking");
        }

    }
    /*Função que atualiza as vitorias e derrotas. True = vitoria*/
    public void Atualiza_pontuacao (boolean ganhou, Jogador jogador){
        if (ganhou) {
            jogador.setVitorias(jogador.getVitorias() + 1);
        }
    }

    public void Atualiza_ranking (Jogador jogador){
        /*fazer algo que não lembro*/

    }



    /*@Action public void closeAboutBox() {
    dispose();
    }*/

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel9 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        lbl_nome = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        txt_ranking = new javax.swing.JTextArea();
        jLabel1 = new javax.swing.JLabel();
        closeButton = new javax.swing.JButton();
        lbl_porcentagem = new javax.swing.JLabel();
        lbl_vitoria = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        lbl_partidas = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance().getContext().getResourceMap(Estatistica.class);
        setTitle(resourceMap.getString("title")); // NOI18N
        setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        setModal(true);
        setName("estatisticaBox"); // NOI18N
        setResizable(false);

        jLabel9.setText(resourceMap.getString("jLabel9.text")); // NOI18N
        jLabel9.setName("jLabel9"); // NOI18N

        jLabel3.setText(resourceMap.getString("jLabel3.text")); // NOI18N
        jLabel3.setName("jLabel3"); // NOI18N

        jLabel10.setText(resourceMap.getString("jLabel10.text")); // NOI18N
        jLabel10.setName("jLabel10"); // NOI18N

        lbl_nome.setText(resourceMap.getString("lbl_nome.text")); // NOI18N
        lbl_nome.setName("lbl_nome"); // NOI18N

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        txt_ranking.setColumns(20);
        txt_ranking.setEditable(false);
        txt_ranking.setRows(5);
        txt_ranking.setName("txt_ranking"); // NOI18N
        jScrollPane1.setViewportView(txt_ranking);

        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        closeButton.setText(resourceMap.getString("closeButton.text")); // NOI18N
        closeButton.setName("closeButton"); // NOI18N
        closeButton.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                closeButtonMouseClicked(evt);
            }
        });

        lbl_porcentagem.setText(resourceMap.getString("lbl_porcentagem.text")); // NOI18N
        lbl_porcentagem.setName("lbl_porcentagem"); // NOI18N

        lbl_vitoria.setText(resourceMap.getString("lbl_vitoria.text")); // NOI18N
        lbl_vitoria.setName("lbl_vitoria"); // NOI18N

        jLabel4.setText(resourceMap.getString("jLabel4.text")); // NOI18N
        jLabel4.setName("jLabel4"); // NOI18N

        lbl_partidas.setText(resourceMap.getString("lbl_partidas.text")); // NOI18N
        lbl_partidas.setName("lbl_partidas"); // NOI18N

        jLabel5.setText(resourceMap.getString("jLabel5.text")); // NOI18N
        jLabel5.setName("jLabel5"); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(21, 21, 21)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel5)
                                    .addComponent(jLabel1)
                                    .addComponent(jLabel3)
                                    .addComponent(jLabel4))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(lbl_partidas)
                                    .addComponent(lbl_vitoria)
                                    .addComponent(lbl_porcentagem)
                                    .addComponent(lbl_nome)))
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 298, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(35, 35, 35))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(9, 9, 9)
                        .addComponent(jLabel9)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jLabel10)
                        .addGap(80, 80, 80))))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(297, Short.MAX_VALUE)
                .addComponent(closeButton)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(21, 21, 21)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(lbl_nome))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(lbl_partidas))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(lbl_vitoria))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(lbl_porcentagem))
                .addGap(54, 54, 54)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel9)
                    .addComponent(jLabel10))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 172, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(closeButton)
                .addContainerGap(29, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void closeButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_closeButtonMouseClicked
        // TODO add your handling code here:
        dispose();
    }//GEN-LAST:event_closeButtonMouseClicked





    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton closeButton;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JLabel lbl_nome;
    private javax.swing.JLabel lbl_partidas;
    private javax.swing.JLabel lbl_porcentagem;
    private javax.swing.JLabel lbl_vitoria;
    private javax.swing.JTextArea txt_ranking;
    // End of variables declaration//GEN-END:variables


    
}
